package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: a
 * Date: 2022-08-29
 * Time: 17:36
 */

//1.继承 Thread 类, 重写 run
class MyThread1 extends Thread{
    @Override
    public void run() {
        System.out.println("thread1");
    }
}

//2.实现 Runnable 接口, 重写 run
class MyThread2 implements Runnable{
    @Override
    public void run() {
        System.out.println("thread2");
    }
}

public class Demo2 {
    public static void main(String[] args) {
        //1.继承 Thread 类, 重写 run
        MyThread1 thread1 = new MyThread1();
        thread1.start();

        //2.实现 Runnable 接口, 重写 run
        Thread thread2 = new Thread(new MyThread2());
        thread2.start();

        //3.继承 Thread 类, 重写 run, 使用匿名内部类
        Thread thread3 = new Thread(){
            @Override
            public void run() {
                System.out.println("thread3");
            }
        };
        thread3.start();

        //4.实现 Runnable 接口, 重写 run, 使用匿名内部类
        Thread thread4 = new Thread(new Runnable(){
            @Override
            public void run() {
                System.out.println("thread4");
            }
        });
        thread4.start();

        //5.使用 lambda 表达式
        Thread thread5 = new Thread(() -> {
            System.out.println("thread5");
        });
        thread5.start();
    }
}
